import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;


public class FormWaiter extends Form implements CommandListener{
	private static String title = "Conectando...";
	private Command cancelar;
	private AppMIDlet midlet;
	private Displayable screen;
	private HttpPoster httpPoster;
	private Gauge gauge;
	

	public FormWaiter(AppMIDlet midlet, HttpPoster httpPoster, Displayable screen) {
		super(title);


		this.httpPoster = httpPoster;
		this.midlet = midlet;
		this.screen = screen;
		
		this.gauge = new Gauge("Enviando Dados...", false, 10, 0);
		this.cancelar = new Command("Cancelar", Command.CANCEL, 1);
		
		this.append(gauge);
		this.addCommand(cancelar);
		this.setCommandListener(this);
		new Thread(new GaugeUpdater(gauge)).start();
	}


	public void commandAction(Command c, Displayable d) {
		if(c == cancelar)
		{
			midlet.showScreen(screen);
			httpPoster.cancel();
		}
		
	}

	

}
